<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActiveScaffold::Actions::Create</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActiveScaffold::Actions::Create</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/vendor/plugins/active_scaffold/lib/actions/create_rb.html">
                vendor/plugins/active_scaffold/lib/actions/create.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000352">after_create_save</a>&nbsp;&nbsp;
      <a href="#M000351">before_create_save</a>&nbsp;&nbsp;
      <a href="#M000348">create</a>&nbsp;&nbsp;
      <a href="#M000353">create_authorized?</a>&nbsp;&nbsp;
      <a href="#M000350">do_create</a>&nbsp;&nbsp;
      <a href="#M000349">do_new</a>&nbsp;&nbsp;
      <a href="#M000346">included</a>&nbsp;&nbsp;
      <a href="#M000347">new</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000346" class="method-detail">
        <a name="M000346"></a>

        <div class="method-heading">
          <a href="#M000346" class="method-signature">
          <span class="method-name">included</span><span class="method-args">(base)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000346-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000346-source">
<pre>
   <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/actions/create.rb, line 3</span>
3:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">included</span>(<span class="ruby-identifier">base</span>)
4:       <span class="ruby-identifier">base</span>.<span class="ruby-identifier">before_filter</span> <span class="ruby-identifier">:create_authorized?</span>, <span class="ruby-identifier">:only</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-identifier">:new</span>, <span class="ruby-identifier">:create</span>]
5:       <span class="ruby-identifier">base</span>.<span class="ruby-identifier">verify</span> <span class="ruby-identifier">:method</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:post</span>,
6:                   <span class="ruby-identifier">:only</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:create</span>,
7:                   <span class="ruby-identifier">:redirect_to</span> =<span class="ruby-operator">&gt;</span> { <span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:index</span> }
8:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000348" class="method-detail">
        <a name="M000348"></a>

        <div class="method-heading">
          <a href="#M000348" class="method-signature">
          <span class="method-name">create</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000348-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000348-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/actions/create.rb, line 27</span>
27:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create</span>
28:       <span class="ruby-identifier">do_create</span>
29: 
30:       <span class="ruby-identifier">respond_to</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">type</span><span class="ruby-operator">|</span>
31:         <span class="ruby-identifier">type</span>.<span class="ruby-identifier">html</span> <span class="ruby-keyword kw">do</span>
32:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:iframe</span>]<span class="ruby-operator">==</span><span class="ruby-value str">'true'</span> <span class="ruby-comment cmt"># was this an iframe post ?</span>
33:             <span class="ruby-identifier">responds_to_parent</span> <span class="ruby-keyword kw">do</span>
34:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">successful?</span>
35:                 <span class="ruby-identifier">render</span> <span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'create.rjs'</span>, <span class="ruby-identifier">:layout</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">false</span>
36:               <span class="ruby-keyword kw">else</span>
37:                 <span class="ruby-identifier">render</span> <span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'form_messages.rjs'</span>, <span class="ruby-identifier">:layout</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">false</span>
38:               <span class="ruby-keyword kw">end</span>
39:             <span class="ruby-keyword kw">end</span>
40:           <span class="ruby-keyword kw">else</span>
41:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">successful?</span>
42:               <span class="ruby-identifier">flash</span>[<span class="ruby-identifier">:info</span>] = <span class="ruby-identifier">as_</span>(<span class="ruby-value str">'Created %s'</span>, <span class="ruby-ivar">@record</span>.<span class="ruby-identifier">to_label</span>)
43:               <span class="ruby-identifier">return_to_main</span>
44:             <span class="ruby-keyword kw">else</span>
45:               <span class="ruby-identifier">render</span>(<span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'create_form'</span>, <span class="ruby-identifier">:layout</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>)
46:             <span class="ruby-keyword kw">end</span>
47:           <span class="ruby-keyword kw">end</span>
48:         <span class="ruby-keyword kw">end</span>
49:         <span class="ruby-identifier">type</span>.<span class="ruby-identifier">js</span> <span class="ruby-keyword kw">do</span>
50:           <span class="ruby-identifier">render</span> <span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'create.rjs'</span>, <span class="ruby-identifier">:layout</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">false</span>
51:         <span class="ruby-keyword kw">end</span>
52:         <span class="ruby-identifier">type</span>.<span class="ruby-identifier">xml</span> { <span class="ruby-identifier">render</span> <span class="ruby-identifier">:xml</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">response_object</span>.<span class="ruby-identifier">to_xml</span>, <span class="ruby-identifier">:content_type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Mime</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span>, <span class="ruby-identifier">:status</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">response_status</span> }
53:         <span class="ruby-identifier">type</span>.<span class="ruby-identifier">json</span> { <span class="ruby-identifier">render</span> <span class="ruby-identifier">:text</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">response_object</span>.<span class="ruby-identifier">to_json</span>, <span class="ruby-identifier">:content_type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Mime</span><span class="ruby-operator">::</span><span class="ruby-constant">JSON</span>, <span class="ruby-identifier">:status</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">response_status</span> }
54:         <span class="ruby-identifier">type</span>.<span class="ruby-identifier">yaml</span> { <span class="ruby-identifier">render</span> <span class="ruby-identifier">:text</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">response_object</span>.<span class="ruby-identifier">to_yaml</span>, <span class="ruby-identifier">:content_type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Mime</span><span class="ruby-operator">::</span><span class="ruby-constant">YAML</span>, <span class="ruby-identifier">:status</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">response_status</span> }
55:       <span class="ruby-keyword kw">end</span>
56:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000347" class="method-detail">
        <a name="M000347"></a>

        <div class="method-heading">
          <a href="#M000347" class="method-signature">
          <span class="method-name">new</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000347-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000347-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/actions/create.rb, line 10</span>
10:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">new</span>
11:       <span class="ruby-identifier">do_new</span>
12: 
13:       <span class="ruby-identifier">respond_to</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">type</span><span class="ruby-operator">|</span>
14:         <span class="ruby-identifier">type</span>.<span class="ruby-identifier">html</span> <span class="ruby-keyword kw">do</span>
15:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">successful?</span>
16:             <span class="ruby-identifier">render</span>(<span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'create_form'</span>, <span class="ruby-identifier">:layout</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>)
17:           <span class="ruby-keyword kw">else</span>
18:             <span class="ruby-identifier">return_to_main</span>
19:           <span class="ruby-keyword kw">end</span>
20:         <span class="ruby-keyword kw">end</span>
21:         <span class="ruby-identifier">type</span>.<span class="ruby-identifier">js</span> <span class="ruby-keyword kw">do</span>
22:           <span class="ruby-identifier">render</span>(<span class="ruby-identifier">:partial</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'create_form'</span>, <span class="ruby-identifier">:layout</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">false</span>)
23:         <span class="ruby-keyword kw">end</span>
24:       <span class="ruby-keyword kw">end</span>
25:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Protected Instance methods</h3>

      <div id="method-M000352" class="method-detail">
        <a name="M000352"></a>

        <div class="method-heading">
          <a href="#M000352" class="method-signature">
          <span class="method-name">after_create_save</span><span class="method-args">(record)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
override this method if you want to do something after the save
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000352-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000352-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/actions/create.rb, line 90</span>
90:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">after_create_save</span>(<span class="ruby-identifier">record</span>); <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000351" class="method-detail">
        <a name="M000351"></a>

        <div class="method-heading">
          <a href="#M000351" class="method-signature">
          <span class="method-name">before_create_save</span><span class="method-args">(record)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
override this method if you want to inject data in the record (or its
associated objects) before the save
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000351-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000351-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/actions/create.rb, line 87</span>
87:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">before_create_save</span>(<span class="ruby-identifier">record</span>); <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000353" class="method-detail">
        <a name="M000353"></a>

        <div class="method-heading">
          <a href="#M000353" class="method-signature">
          <span class="method-name">create_authorized?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
The default security delegates to <a
href="../../ActiveRecordPermissions.html">ActiveRecordPermissions</a>. You
may override the method to customize.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000353-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000353-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/actions/create.rb, line 94</span>
94:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create_authorized?</span>
95:       <span class="ruby-identifier">authorized_for?</span>(<span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:create</span>)
96:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000350" class="method-detail">
        <a name="M000350"></a>

        <div class="method-heading">
          <a href="#M000350" class="method-signature">
          <span class="method-name">do_create</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
A somewhat complex method to actually <a
href="Create.html#M000348">create</a> a <a
href="Create.html#M000347">new</a> record. The complexity is from support
for subforms and associated records. If you want to customize this
behavior, consider using the <tt><a
href="Create.html#M000351">before_create_save</a></tt> and <tt><a
href="Create.html#M000352">after_create_save</a></tt> callbacks.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000350-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000350-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/actions/create.rb, line 70</span>
70:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">do_create</span>
71:       <span class="ruby-keyword kw">begin</span>
72:         <span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">model</span>.<span class="ruby-identifier">transaction</span> <span class="ruby-keyword kw">do</span>
73:           <span class="ruby-ivar">@record</span> = <span class="ruby-identifier">update_record_from_params</span>(<span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">model</span>.<span class="ruby-identifier">new</span>, <span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">create</span>.<span class="ruby-identifier">columns</span>, <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:record</span>])
74:           <span class="ruby-identifier">apply_constraints_to_record</span>(<span class="ruby-ivar">@record</span>, <span class="ruby-identifier">:allow_autosave</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>)
75:           <span class="ruby-identifier">before_create_save</span>(<span class="ruby-ivar">@record</span>)
76:           <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">successful</span> = [<span class="ruby-ivar">@record</span>.<span class="ruby-identifier">valid?</span>, <span class="ruby-ivar">@record</span>.<span class="ruby-identifier">associated_valid?</span>].<span class="ruby-identifier">all?</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">v</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>} <span class="ruby-comment cmt"># this syntax avoids a short-circuit</span>
77:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">successful?</span>
78:             <span class="ruby-ivar">@record</span>.<span class="ruby-identifier">save!</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@record</span>.<span class="ruby-identifier">save_associated!</span>
79:             <span class="ruby-identifier">after_create_save</span>(<span class="ruby-ivar">@record</span>)
80:           <span class="ruby-keyword kw">end</span>
81:         <span class="ruby-keyword kw">end</span>
82:       <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">RecordInvalid</span>
83:       <span class="ruby-keyword kw">end</span>
84:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000349" class="method-detail">
        <a name="M000349"></a>

        <div class="method-heading">
          <a href="#M000349" class="method-signature">
          <span class="method-name">do_new</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
A simple method to find and prepare an example <a
href="Create.html#M000347">new</a> record for the form May be overridden to
customize the behavior (add default values, for instance)
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000349-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000349-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/actions/create.rb, line 62</span>
62:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">do_new</span>
63:       <span class="ruby-ivar">@record</span> = <span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">model</span>.<span class="ruby-identifier">new</span>
64:       <span class="ruby-identifier">apply_constraints_to_record</span>(<span class="ruby-ivar">@record</span>)
65:       <span class="ruby-ivar">@record</span>
66:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>